<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Register Result</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
 <%
     
     String username=request.getParameter("username");
     String oldpassword=request.getParameter("oldpasswd");
     String password=request.getParameter("passwd");
     String repassword=request.getParameter("repasswd");
     String url="jdbc:mysql://localhost:3306/java_web_db?user=root&password=root";
     Class.forName("com.mysql.jdbc.Driver");
     Connection Con=DriverManager.getConnection(url);
     //创建数据库连接
     Statement stm=null;
     ResultSet rs=null;
          stm=Con.createStatement();
          String sql ="select * from users where user_name='"+username+"' and password='"+oldpassword+"'";
          
          rs=stm.executeQuery(sql);
          if(rs.next())
          
          { String query1="delete from users where user_name='"+username+"' and password='"+oldpassword+"'";
            stm.executeUpdate(query1);
            String query2="insert into users values ('"+username+"','"+password+"')";
            stm.executeUpdate(query2);
            out.println("已修改密码！<a href=\"http://127.0.0.1:8080/Java Web/login.jsp\">点击返回登录页面</a>");}
            else{
                 out.println("不存在该用户或密码输入错误，返回更改密码界面重新更改或返回登录界面进行登录！<a href=\"http://127.0.0.1:8080/Java Web/login.jsp\">点击返回登录页面</a>");
                 out.println("<a href=\"http://127.0.0.1:8080/Java Web/alter.jsp\">点击返回更改密码页面</a>");}
                 
          
       rs.close();//关闭ResultSet对象
       stm.close();//关闭Statement对象
       Con.close();//关闭Connection对象
%>
  </body>
</html>
